<?php
class SysUserModel extends CommonModel {
    
    protected $_auto                = array ( 
                                             array('operate_id', 'get_login_user_id', 3, 'function'),
                                             array('create_time', 'get_date', 1, 'function'),
                                             array('update_time', 'get_date', 3, 'function'),
                                      );
    protected $_str_order_by        = 'CONVERT(user_name USING gbk) ASC';
    
    /**
     * Get user info
     * 
     * @param  $intUserId
     * @return array
     * @author andy
     */
    public function get_info( $intUserId ) {
        
        $arr_info  = $this->where('user_id = ' . $intUserId)->find();

        return $arr_info;
    }
    
    /**
     * Get user info by user name
     * 
     * @param  $stUserName
     * @param  $strPassword
     * @return array
     * @author andy
     */
    public function get_info_by_user_name( $stUserName, $strPassword ) {

        $arr_info  = $this->where('status = 1 AND user_name = "' . $stUserName . '" AND password = "' . md5($strPassword) . '"')->find();

        return $arr_info;
    }
    
    /**
     * Update user info
     * 
     * @param  $intUserId
     * @return array
     * @author andy
     */
    public function update_info( $intUserId ) {
        
        $obj_model                  = D('SysUser');
        $obj_model->where('user_id = ' . $intUserId)->find();
        $obj_model->last_login_time = date('Y-m-d H:i:s');
        $obj_model->login_ip        = get_client_ip();
        $obj_model->update_time     = date('Y-m-d H:i:s');

        return $obj_model->save();
    }
}